<template>
  <div>
    <div class="login">
      <div class="login-nav">
        <div class="login-nav-logo">
          <img src="../assets/icon/loginlogo.png" alt="" width="150px" />
        </div>
        <div class="login-nav-gg" @click="HomeView">逛一逛</div>
      </div>

      <div class="welcometext">
        <div class="chinese">找回密码！</div>
        <div class="english">Find password</div>
      </div>

      <!-- 登录框 -->
      <div class="loginInfo">
        <van-form @submit="retrievePassword">
          <van-field
            v-model="phone"
            name="手机号"
            label="手机号"
            placeholder="手机号"
            autocomplete="off"
          />
          <van-field
            v-model="password"
            :type="showLoginpassword ? 'text' : 'password'"
            name="密码"
            label="密码"
            autocomplete="off"
            :right-icon="showLoginpassword ? 'eye-o' : 'closed-eye'"
            @click-right-icon="toggleEye('showLoginpassword')"
            placeholder="密码必须为字母开头"
          />
          <div class="forgotpas" @click="Tologin">已有帐号,立即登录</div>
          <div style="margin: 60px 16px 40px 16px">
            <van-button round block type="info" native-type="submit"
              >提交</van-button
            >
          </div>
          <div style="margin: 16px">
            <van-button round block native-type="submit" @click="Tologin">返回</van-button>
          </div>
        </van-form>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Newpassword",
  data() {
    return {
      password: "",
      phone: "13790915327",
      //登录密码显示隐藏
      showLoginpassword: false,
      appkey: "U2FsdGVkX19WSQ59Cg+Fj9jNZPxRC5y0xB1iV06BeNA=",
    };
  },
  created() {},
  methods: {
    retrievePassword() {
      //验证密码
      let RegPassword = /^[A-Za-z][A-Za-z\d]{5,15}$/;
      if (
        !RegPassword.test(this.password) ||
        this.password == ""
      ) {
        this.$toast("密码格式错误");
        return;
      }
      let str = `appkey=${this.appkey}&phone=${this.phone}&password=${this.password}`;
      this.axios({
        method: "post",
        url: "/retrievePassword",
        data: str,
      }).then((res) => {
        console.log(res);
      });
    },
    //逛一逛
    HomeView() {
      this.$toast.loading({
        message: "加载中...",
        forbidClick: true,
        duration: 0,
      });
      setTimeout(() => {
        this.$router.push({ name: "Home" });
        this.$toast.clear();
      }, 3000);
    },
    //点击切换密码显示隐藏
    toggleEye(key) {
      this[key] = !this[key];
    },
    //跳转登录
    Tologin() {
      this.$router.push({ name: "Login" });
    },
  },
};
</script>

<style lang="less" scoped>
.forgotpas {
  color: #6A6867;
  font-size: 12px ;
  width: 200px;
  margin-top: 15px;
  margin-left: 265px;
}
.loginInfo {
  margin-top: 40px;
}
.english {
  margin-left: 10px;
  font-size: 14px;
  margin-top: 20px;
  color: #83838b;
}
.chinese {
  margin-left: 10px;
  margin-top: 80px;
  font-weight: bold;
  font-size: 24px;
  color: #646566;
}
.login-nav-gg {
  margin-top: 3px;
  color: blue;
}
.login-nav {
  display: flex;
  justify-content: space-between;
  padding: 10px;
  box-sizing: border-box;
  align-items: center;
  height: 50px;
  font-size: 16px;
}
.login {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #fff;
}
</style>